import React, { Component } from 'react';
import { inject, observer } from 'mobx-react';
import { WeaDialog, WeaLocaleProvider } from 'ecCom';
import { onCloseHandle } from '../util';

const getLabel = WeaLocaleProvider.getLabel;

@inject('listStore')
@observer
export default class Home extends Component {
  static defaultProps = {
    prefixCls: 'group-voting',
  }

  constructor(props) {
    super(props);

    this.state = {
      visible: false,
    };
    this.defaultMD = null;
    window.setLayoutWindow = window;
    window.setDialogFullWindow = true;
    window.inIframe = true;
  }

  componentDidMount() {
    this.setState({ visible: true });
    if (window.em) {
      let that = this;
      em.ready(() => {
        em.setPageReload({
          setvalue: 1, // 1表示每次都需要重新加载页面（默认） 2表示保持页面无需重新加载，
          success: (res) => {
          },
        });
      });
    }
  }

  render() {
    const { prefixCls, children, listStore: { title } } = this.props;
    const { visible } = this.state;
    let groupTitle = title ? `${getLabel('514291', '群投票')}-${title}` : getLabel('514291', '群投票');
    return (
      <WeaLocaleProvider ecId={`${this && this.props && this.props.ecId || ''}_WeaLocaleProvider@6sxg91`}>
        <div className={prefixCls}>
          <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@sor0fg`}
            icon="icon-portal-reportform"
            iconBgcolor="#0079DE"
            title={groupTitle}
            visible={visible}
            ref={el => (this.defaultMD = el)}
            className={`${prefixCls}-dialog`}
            onCancel={() => { onCloseHandle(); this.setState({ visible: false }); }}
            browserModalProps={
              {
                transitionName: 'none',
                draggable: false,
                visibleOnClose: true,
                hideClear: true,
              }
            }
          >
            {children}
          </WeaDialog>
        </div>
      </WeaLocaleProvider>
    );
  }
}
